package com.jianbing.north.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.jianbing.common.utils.SecurityUtils;
import org.apache.ibatis.annotations.Param;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.jianbing.common.annotation.Log;
import com.jianbing.common.core.controller.BaseController;
import com.jianbing.common.core.domain.AjaxResult;
import com.jianbing.common.enums.BusinessType;
import com.jianbing.north.domain.NorthQuesStem;
import com.jianbing.north.service.INorthQuesStemService;
import com.jianbing.common.utils.poi.ExcelUtil;
import com.jianbing.common.core.page.TableDataInfo;

/**
 * 题干Controller
 * 
 * @author ruoyi
 * @date 2024-06-20
 */
@RestController
@RequestMapping("/north/stem")
public class NorthQuesStemController extends BaseController
{
    @Autowired
    private INorthQuesStemService northQuesStemService;

    /**
     * 查询题干列表
     */
    //  @PreAuthorize("@ss.hasPermi('north:stem:list')")
    @GetMapping("/list")
    public TableDataInfo list(NorthQuesStem northQuesStem)
    {
        startPage();
        List<NorthQuesStem> list = northQuesStemService.selectNorthQuesStemList(northQuesStem);
        return getDataTable(list);
    }

    /**
     * 导出题干列表
     */
    //  @PreAuthorize("@ss.hasPermi('north:stem:export')")
    @Log(title = "题干", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NorthQuesStem northQuesStem)
    {
        List<NorthQuesStem> list = northQuesStemService.selectNorthQuesStemList(northQuesStem);
        ExcelUtil<NorthQuesStem> util = new ExcelUtil<NorthQuesStem>(NorthQuesStem.class);
        util.exportExcel(response, list, "题干数据");
    }

    /**
     * 获取题干详细信息
     */
    //  @PreAuthorize("@ss.hasPermi('north:stem:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(northQuesStemService.selectNorthQuesStemById(id));
    }

    /**
     * 新增题干
     */
    //  @PreAuthorize("@ss.hasPermi('north:stem:add')")
    @Log(title = "题干", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NorthQuesStem northQuesStem)
    {
        return toAjax(northQuesStemService.insertNorthQuesStem(northQuesStem));
    }

    /**
     * 修改题干
     */
    //  @PreAuthorize("@ss.hasPermi('north:stem:edit')")
    @Log(title = "题干", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NorthQuesStem northQuesStem)
    {
        return toAjax(northQuesStemService.updateNorthQuesStem(northQuesStem));
    }

    /**
     * 删除题干
     */
    //  @PreAuthorize("@ss.hasPermi('north:stem:remove')")
    @Log(title = "题干", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(northQuesStemService.deleteNorthQuesStemByIds(ids));
    }

    //  @PreAuthorize("@ss.hasPermi('north:stem:query')")
    @GetMapping("/ques/p2")
    public AjaxResult getQuesP2(@Param("difficulty") Long difficulty)
    {
        Long part = 2L;
        Long userId = SecurityUtils.getUserId();
        return success(northQuesStemService.selectNorthQuesByUserIdAndPartAndDifficulty(userId,part,difficulty));
    }

    //  @PreAuthorize("@ss.hasPermi('north:stem:query')")
    @GetMapping("/ques/p3")
    public AjaxResult getQuesP3(@Param("difficulty") Long difficulty)
    {
        Long userId = SecurityUtils.getUserId();
        return success(northQuesStemService.selectP3QuesByUserIdAndDifficulty(userId,difficulty));
    }


}
